package com.cn.sl.server.api.system.user.model.dto

import com.cn.sl.server.api.system.department.model.dto.DepartmentDto
import com.cn.sl.server.api.system.file.model.dto.SysFileDto
import com.cn.sl.server.api.system.role.model.dto.RoleDto
import com.cn.sl.server.api.system.user.model.entity.AdminUserEntity
import com.cn.sl.server.api.system.user.model.entity.UserStatus
import io.swagger.v3.oas.annotations.media.Schema

@Schema(description = "用户信息")
data class AdminUserDto(
    @field:Schema(description = "用户id")
    val id: Long,
    @field:Schema(description = "头像id")
    val avatarId: Long?,
    @field:Schema(description = "头像")
    val avatar: SysFileDto?,
    /**
     * 用户名
     */
    @field:Schema(description = "用户名")
    var username: String = "",

    /**
     * 联系电话
     */
    @field:Schema(description = "联系电话")
    var phone: String = "",
    @field:Schema(description = "角色")
    var roles: List<RoleDto>,
    @field:Schema(description = "状态")
    var status: UserStatus,
    @field:Schema(description = "部门id")
    var departmentId: Long?,
    @field:Schema(description = "部门")
    var department: DepartmentDto?,
) {
    constructor(entity: AdminUserEntity) : this(
        entity.id,
        entity.avatarId,
        entity.avatar?.let { SysFileDto(it) },
        entity.username,
        entity.phone,
        entity.roles.map { RoleDto(it) },
        entity.status,
        entity.departmentId,
        entity.department?.let { DepartmentDto(it) }
    )
}